<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
      
      <template #images="{ record }">
          <div style="display:flex;">
            <a-image-preview-group infinite>
              <div style="margin-right:6px" v-for="(item,index) in record.images" :key="index">
                <a-image
                  width="60"
                  :src="item"
                />
              </div>
            </a-image-preview-group>
            
          </div>
      </template>
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import predictionLog from '@/api/prediction/predictionLog'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()
const prediction_id = ref()

const open = (row) => {
    prediction_id.value = row.id
    crudRef.value.requestData();
};

const numberOperation = (newValue, id, numberName) => {
  predictionLog.numberOperation({ id, numberName, numberValue: newValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}

const switchStatus = (statusValue, id, statusName) => {
  predictionLog.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'flyos_prediction_log',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  autoRequest:false,
  operationWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: predictionLog.getList,
  recycleApi: predictionLog.getRecycleList,
  add: {
    show: false,
    api: predictionLog.save,
    auth: ['prediction:log:save']
  },
  edit: {
    show: false,
    api: predictionLog.update,
    auth: ['prediction:log:update']
  },
  delete: {
    show: false,
    api: predictionLog.deletes,
    auth: ['prediction:log:delete'],
    realApi: predictionLog.realDeletes,
    realAuth: ['prediction:log:realDeletes']
  },
  recovery: {
    show: false,
    api: predictionLog.recoverys,
    auth: ['prediction:log:recovery']
  },
  import: {
    show: false,
    url: 'prediction/log/import',
    templateUrl: 'prediction/log/downloadTemplate',
    auth: ['prediction:log:import']
  },
  export: {
    show: true,
    url: 'prediction/log/export',
    auth: ['prediction:log:export']
  },
  beforeRequest: (params) => {
		params.type = 1;
		params.prediction_id = prediction_id.value;
	},
  afterRequest: (params) => {
		console.log(params, "后置方法");
		params.map((v, i) => {
			if (v.images == '') {
				v.images = [];
			} else {
				v.images = v.images.split(',');
			}
		});
	},
})

const columns = reactive([
  {
    title: "",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入"
    }
  },
  {
    title: "类型",
    dataIndex: "type",
    formType: "select",
    search: true,
    dict: {
      data: [
        {
          label: "巡查上报",
          value: "1"
        },
        {
          label: "单证上报",
          value: "2"
        },
        {
          label: "用户备注",
          value: "3"
        }
      ],
      translation: true
    }
  },
  {
    title: "预报ID",
    dataIndex: "prediction_id",
    formType: "input",
    search: true
  },
  {
    title: "巡查件数",
    dataIndex: "number",
    formType: "input",
    search: true
  },
  {
    title: "备注",
    dataIndex: "remark",
    formType: "input",
    addDisplay: false,
    editDisplay: false
  },
  {
    title: "巡查图片",
    dataIndex: "images",
    formType: "input",
    addDisplay: false,
    editDisplay: false
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    search: true,
    addDisplay: false,
    editDisplay: false,
    sortable: {
      sortDirections: [
        "ascend",
        "descend"
      ],
      sorter: true
    },
    showTime: true
  },
  {
    title: "修改时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "创建人",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "修改人",
    dataIndex: "updated_by",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  }
])
defineExpose({ open });
</script>
<script> export default { name: 'prediction:log' } </script>